home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / tutorials / geometer / lookup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.8 KB  |  78 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. #include "parse.h"
  19. #include <strings.h>
  20.  
  21. // this is as crude as you can get
  22.  
  23. struct table {
  24.     symtableentry  *data;
  25.     long        count;
  26.     long        maxsize;
  27. };
  28.  
  29. long newtable(long size)
  30. {
  31.     table *t = new table;
  32.     t->data = new symtableentry[size];
  33.     t->count = 0;
  34.     t->maxsize = size;
  35.     return (long)t;
  36. }
  37.  
  38. void cleartable(long tt)
  39. {
  40.     table *t = (table *)tt;
  41.     for (long i = 0; i < t->count; i++) {
  42.     *t->data[i].symbol = 0;
  43.  
  44.     t->data[i].p = 0;
  45.     }
  46.     t->count = 0;
  47. }
  48.  
  49. symtableentry *lookup(long tt, char *str)
  50. {
  51.     table *t = (table *)tt;
  52.     for (long i = 0; i < t->count; i++) {
  53.     if (strcmp(t->data[i].symbol, str) == 0)
  54.         return &t->data[i];
  55.     }
  56.     return 0;
  57. }
  58.  
  59. void removeentry(long tt, char *str)
  60. {
  61.     table *t = (table *)tt;
  62.     for (long i = 0; i < t->count; i++) {
  63.     if (strcmp(t->data[i].symbol, str) == 0)
  64.         t->data[i].symbol[0] = 0;
  65.     }
  66. }
  67.  
  68. symtableentry *addentry(long tt, char *str, reservedword value)
  69. {
  70.     symtableentry *st;
  71.     table *t = (table *)tt;
  72.     st = &t->data[t->count++];
  73.     strcpy(st->symbol, str);
  74.     st->value = value;
  75.     return st;
  76. }
  77.  
  78.